package com.hzcx.app.simplechat.ui.moment.presenter;

import android.content.Context;

import com.hzcx.app.simplechat.api.BaseDialogObserver;
import com.hzcx.app.simplechat.api.BaseObserver;
import com.hzcx.app.simplechat.base.BaseEmptyBean;
import com.hzcx.app.simplechat.base.BasePresenter;
import com.hzcx.app.simplechat.model.MomentModel;
import com.hzcx.app.simplechat.ui.moment.bean.MomentCommentBean;
import com.hzcx.app.simplechat.ui.moment.bean.MomentInfoBean;
import com.hzcx.app.simplechat.ui.moment.contract.MomentInfoContract;

import java.util.List;

public class MomentInfoPresenter extends BasePresenter<MomentInfoContract.View> implements MomentInfoContract.Presenter {


    /**
     * 获取动态详情
     *
     * @param context
     * @param id
     */
    @Override
    public void getMomentInfo(Context context, int id) {
        MomentModel.getMomentInfo(context, id, new BaseDialogObserver<MomentInfoBean>(context) {
            @Override
            protected void onSuccess(MomentInfoBean data) {
                mView.momentInfoResult(data);
            }
        });
    }

    /**
     * 评论
     *
     * @param context
     * @param dynamic_id
     * @param review_content
     * @param by_review_id
     */
    @Override
    public void momentComment(Context context, int dynamic_id, String review_content, String by_review_id) {
        MomentModel.momentComment(context, dynamic_id, review_content, by_review_id, new BaseDialogObserver<MomentCommentBean>(context) {
            @Override
            protected void onSuccess(MomentCommentBean data) {
                mView.commentSuccess(data);
            }
        });
    }

    /**
     * 获取动态评论列表
     *
     * @param context
     * @param id
     * @param page
     */
    @Override
    public void getMomentCommentList(Context context, int id, int page) {
        MomentModel.getMomentCommentList(context, id, page, new BaseObserver<List<MomentCommentBean>>() {
            @Override
            protected void onSuccess(List<MomentCommentBean> data) {
                mView.commentResult(data);
            }

            @Override
            public void onFailure(Throwable e, String errorMsg) {
                super.onFailure(e, errorMsg);
                mView.onFail();
            }
        });
    }

    /**
     * 点赞
     *
     * @param context
     * @param id
     */
    @Override
    public void momentFabulous(Context context, int id) {
        MomentModel.momentFabulous(context, id, new BaseObserver<BaseEmptyBean>() {
            @Override
            protected void onSuccess(BaseEmptyBean data) {
                mView.fabulousSuccess();
            }
        });
    }

    /**
     * 删除动态
     *
     * @param context
     * @param id
     */
    @Override
    public void deleteMoment(Context context, int id) {
        MomentModel.deleteMoment(context, id, new BaseDialogObserver<BaseEmptyBean>(context) {
            @Override
            protected void onSuccess(BaseEmptyBean data) {
                mView.deleteSuccess();
            }
        });
    }

    /**
     * 删除评论
     *
     * @param context
     * @param id
     * @param pos
     */
    @Override
    public void deleteComment(Context context, int id, int pos) {
        MomentModel.deleteComment(context, id, new BaseDialogObserver<BaseEmptyBean>(context) {
            @Override
            protected void onSuccess(BaseEmptyBean data) {
                mView.deleteCommentSuccess(pos);
            }
        });
    }

    /**
     * 屏蔽动态
     *
     * @param context
     * @param id
     */
    @Override
    public void shieldMoment(Context context, int id) {
        MomentModel.shieldMoment(context, id, new BaseDialogObserver<BaseEmptyBean>(context) {
            @Override
            protected void onSuccess(BaseEmptyBean data) {
                mView.shieldSuccess(id);
            }
        });
    }
}
